//
//  MyBillsModel.m
//  HTP
//
//  Created by 王鑫 on 15/11/10.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "MyOrderModel.h"
//courseName = "\U79d1\U5b66";
//ordCode = QMJJM028935298;
//ordCourseTime = 4;
//ordCreatTime = "2015-11-14 12:18:19";
//ordId = 31;
//ordRealValue = 0;
//ordSinglePrice = 65;
//ordStatus = 3;
//ordTime = "";
//ordType = 0;
//ordValue = 260;
//teacherName = "\U4eba\U6c11\U6559\U5e08";
//teacherPhotoPath
@implementation MyOrderModel
-(BOOL)saveBean{
    OrderData *order = [OrderData findFirstByAttribute:@"ordId" withValue:self.ordId];
    if (order == nil) {
        order = [OrderData createEntity];
    }
    order.courseName = self.courseName;
    order.ordCode = self.ordCode;
    order.ordCourseTime = self.ordCourseTime;
    order.ordCreatTime = self.ordCreatTime;
    order.ordId = self.ordId;
    order.ordRealValue = self.ordRealValue;
    order.ordSinglePrice = self.ordSinglePrice;
    order.ordStatus = self.ordStatus;
    order.ordTime = self.ordTime;
    order.ordType = self.ordType;
    order.ordValue = self.ordValue;
    order.teacherName = self.teacherName;
    order.teacherPhotoPath = self.teacherPhotoPath;
    order.parentId = [NSNumber numberWithInt:[[USERCONTENT getUserParentId] intValue]];
    return  [XLCoreDataManager save];
}
+(id)initWithOrderData:(OrderData *)order{
    MyOrderModel *myOrder = [[MyOrderModel alloc] init];
    myOrder.courseName = order.courseName;
    myOrder.ordCode = order.ordCode;
    myOrder.ordCourseTime = order.ordCourseTime;
    myOrder.ordCreatTime = order.ordCreatTime;
    myOrder.ordId = order.ordId;
    myOrder.ordRealValue = order.ordRealValue;
    myOrder.ordSinglePrice = order.ordSinglePrice;
    myOrder.ordStatus = order.ordStatus;
    myOrder.ordTime = order.ordTime;
    myOrder.ordType = order.ordType;
    myOrder.ordValue = order.ordValue;
    myOrder.teacherName = order.teacherName;
    myOrder.teacherPhotoPath = order.teacherPhotoPath;
    return myOrder;
}
+(NSArray *)creatMyOrders:(NSArray *)orderData{
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    [orderData enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        OrderData *order = (OrderData *)obj;
        [dataArray addObject:[MyOrderModel initWithOrderData:order]];
    }];
    return [NSArray arrayWithArray:dataArray];
}

@end
